﻿using Inovout.Organizations.Models;
using Inovout.People.Models;
using Inovout.Services;
using NHibernate.Criterion;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Inovout.Organizations.Services
{
    public class EmployeeService : RepositoryService<Employee>, IEmployeeService
    {

        public List<Employee> FindByKey(string key, OrganizationUnit organizationUnit)
        {         
            if (organizationUnit != null)
            {
                return (List<Employee>)base.Repository.FindAll(Restrictions.Eq("Organization.Id", (object)organizationUnit.Id));            
            }
            else
            {
                IRepositoryService<Employee> employeeService = ComponentRegistry.Resolve<IRepositoryService<Employee>>();
                return employeeService.Query().ToList<Employee>();
            }
           
        }

        public Employee FindByPhone(Phone phone)
        {
             return base.Repository.Find(Restrictions.Eq("Person.Id", (object)phone.Person.Id));   
        }
        
    }
}
